/**
 * 
 */
package info.niwota.home.fm;

import info.niwota.home.R;

import java.net.URI;
import java.util.Date;

import x.java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;

/**
 * View file properties when no other applications are available for MIME type:
 * application/octet-stream
 * 
 * @author qiangli
 * 
 */
public class FilePropertyViewActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.webbrowser);
		load();
	}

	private void load() {
		try {
			WebView wv = (WebView) findViewById(R.id.webview);
			;
			StringBuilder sb = new StringBuilder();
			Intent i = getIntent();
			if (i != null) {
				Uri uri = i.getData();
				if (uri != null) {
					String p = uri.getPath();
					File f = new File(p);
					// String name = f.getName();
					String path = f.getPath();
					URI real = f.toRealURI();
					long len = f.length();
					long modified = f.lastModified();
					// String mime = f.getContentType();
					// boolean read = f.canRead();
					// boolean write = f.canWrite();
					// boolean exec = f.canExecute();
					// boolean mount =
					// FileSystem.getFileSystem().isMountPoint(p);
					// TODO with a template?
					final String br = "<br />";
					sb.append(path);
					sb.append(br);
					sb.append(len);
					sb.append(br);
					sb.append(new Date(modified));
					sb.append(br);
					sb.append(real);
					sb.append(br);
				}
			}
			wv.loadData(sb.toString(), "text/html", "UTF-8");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
